﻿using MediatR;
using SlaughterItem.Common.Domains.Check_Ins;
using SlaughterItem.Common.Domains.ListWeek2;
using SlaughterItem.Common.Domains.PORk;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace GetSlaughterItem.API.Application.Commands.Week03.Reports
{
    public class WhiteporkReportsQueryHandler : IRequestHandler<WhiteporkReportsQueryCommand, Result>
    {
        /// <summary>
        /// 白条称重明细
        /// </summary>
        private readonly IBaseRepositoryGet<WhiteporkData> whiteporkDatarepository;
        /// <summary>
        /// 进场登记
        /// </summary>
        private readonly IBaseRepositoryGet<CheckIn> checkInRepository;
        /// <summary>
        /// 活畜称重
        /// </summary>
        private readonly IBaseRepositoryGet<LiveAnimals> liveAnimalsRepository;
        /// <summary>
        ///批宰计划
        /// </summary>
        private readonly IBaseRepositoryGet<Slaughter> slaughterRepository;
        /// <summary>
        ///供应商
        /// </summary>
        private readonly IBaseRepositoryGet<Supplier> supplierRepository;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="whiteporkDatarepository"></param>
        /// <param name="slaughterRepository"></param>
        /// <param name="liveAnimalsRepository"></param>
        /// <param name="checkInRepository"></param>
        /// <param name="supplierRepository"></param>
        public WhiteporkReportsQueryHandler(IBaseRepositoryGet<WhiteporkData> whiteporkDatarepository, IBaseRepositoryGet<Slaughter> slaughterRepository, IBaseRepositoryGet<LiveAnimals> liveAnimalsRepository, IBaseRepositoryGet<CheckIn> checkInRepository, IBaseRepositoryGet<Supplier> supplierRepository)
        {
            this.whiteporkDatarepository = whiteporkDatarepository;
            this.slaughterRepository = slaughterRepository;
            this.liveAnimalsRepository = liveAnimalsRepository;
            this.checkInRepository = checkInRepository;
            this.supplierRepository = supplierRepository;
        }
        /// <summary>
        /// 业务逻辑
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(WhiteporkReportsQueryCommand request, CancellationToken cancellationToken)
        {
            var result= new Result() { Code=(int)CommonErrorCode.Success};

            var list = (from a in whiteporkDatarepository.GetAll()
                        //join b in slaughterRepository.GetAll()
                        //on a.SlaughterNo equals b.SlaughterNo
                        //join c in liveAnimalsRepository.GetAll()
                        //on b.LiveAnimalsId equals c.LiveAnimalsId
                        //join d in checkInRepository.GetAll()
                        //on c.CheckInId equals d.CheckInId
                        //join e in supplierRepository.GetAll()
                        //on d.SupplierId equals e.SupplierId
                        //where a.IsDel==false
                        select new
                        {
                            a.WhiteWeighingId,
                            a.WhiteWeighingDate,
                            a.WhiteWeighingDesc,
                            a.SlaughterNo,
                            a.GoodsMinute,
                            a.SkinWeight,
                            a.GrossWeight,
                            a.NetWeight,
                            a.WeighingNum,
                            //b.SlaughterMaxType,
                            //c.LiveAnimalsDocument,
                            //d.CheckInNo,
                            //e.SupplierName,

                        }).ToList();



            result.Data = list;
            return result;
        }
    }
}
